﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model;
using YouHP.BLL;
using YouHP.Utility;

namespace YouHP.Pages.Ajax
{
    public class PopupAjax : BasePage
    {
        string strShow = "";
        StringBuilder sb = new StringBuilder();
        UserInfo userInfo = new UserInfo();
        PatientRecordInfo patientRecordInfo = new PatientRecordInfo();
        DiseaseInfo diseaseInfo = new DiseaseInfo();
        List<SymptomHistoryInfo> symtomList = new List<SymptomHistoryInfo>();
        List<TreatmentHistoryInfo> treatmentList = new List<TreatmentHistoryInfo>();
        List<IndicatorHistoryInfo> indicatorList = new List<IndicatorHistoryInfo>();
        WeightHistoryInfo weightInfo = new WeightHistoryInfo();  

       
        
        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            int userId = -1;
            userId = RequestTools.GetQueryInt("uid", 0);
            GetUserData(userId);
            GenerateFormat();
            sb.Append(strShow);

            ResponseXML(sb);
            return;
        }

        public PopupAjax()
        {
            //GenerateFormat();
            //sb.Append(strShow);

            //ResponseXML(sb);
        }

        protected void GetUserData(int userID)
        {
            userInfo = UserBLL.Instance.GetUserInfo(userID);
            patientRecordInfo = PatientBLL.Instance.GetPatientRecordInfo(userID);
            diseaseInfo = DiseaseBLL.Instance.GetDiseaseInfo(patientRecordInfo.DiseaseId);
            symtomList = PatientSymptomBLL.Instance.GetPrimarySymptoms(patientRecordInfo.Id);
            treatmentList = PatientTreatmentBLL.Instance.GetBindingTreatmentList(patientRecordInfo.Id);
            indicatorList = PatientIndicatorBLL.Instance.GetCurrentIndicatorList(patientRecordInfo.Id);
            weightInfo = PatientBLL.Instance.GetCurrentWeight(patientRecordInfo.Id);
        }

        protected void GenerateFormat()
        {
            strShow += "            <div id='content'>";
            strShow += "            <div id='popupcontent'>";
            strShow += "                <div id='UIPageChangeWeb'>";
            strShow += "                    <div id='popup_basic'>";
            strShow += "                        <div class='popup_image_div' >";
            strShow += "                            <img src='"+userInfo.Avatar+"' class='popup_image' />";
            strShow += "                        </div>";
            strShow += "                        <div class='basic_info'>";
            strShow += "                            <li><span>用户名：</span>"+userInfo.UserName+"</li>";
            strShow += "                            <li><span>性别：</span>"+userInfo.Gender+"</li>";
            strShow += "                            <li><span>年龄：</span>"+userInfo.Age+"</li>";
            strShow += "                            <li><span>地区：</span> "+userInfo.Province+"</li>";
            strShow += "                        </div>";
            strShow += "                    </div>";
            strShow += "                    <div id='popup_disease'>";
            strShow += "                        <div class='disease_info'>";
            strShow += "                            <div class='disease_left'><img src='/support/alpha/images/popup/popup_items.gif'/>&nbsp;疾病：</div><div class='disease_right'>";
            strShow += "                      <a href=" + "../Disease.aspx?id=" + diseaseInfo.Id + " class='linkclass' style='text-decoration:underline;font-size=11pt;'><font color='Green'>" + diseaseInfo.Name + "</font></a>";
            strShow += "                            </div>";
            strShow += "                        </div>";
            strShow += "                        <div class='disease_info'>";
            strShow += "                            <div class='disease_left'><img src='/support/alpha/images/popup/popup_items.gif'/>&nbsp;体重：</div><div class='disease_right'>"+weightInfo.DataValue+"公斤</div>";
            strShow += "                        </div>";
            strShow += "                        <div class='disease_info'>";
            strShow += "                            <div class='disease_left'><img src='/support/alpha/images/popup/popup_items.gif'/>&nbsp;症状：</div><div class='disease_right'>";
            foreach (SymptomHistoryInfo info in symtomList)
            {
                strShow += "<a href=" + "../Symptom.aspx?id=" + info.SymptomId + " class='linkclass' style='text-decoration:underline;font-size=12pt; color='Green''><font color='Green'>" + info.SymptomName + "</font></a>";
            }
            strShow += "                             </div>";
            strShow += "                        </div>";
            strShow += "                        <div  class='disease_info'>";
            strShow += "                            <div  class='disease_left'><img src='/support/alpha/images/popup/popup_items.gif'/>&nbsp;指标：</div><div class='disease_right'>";
            foreach (IndicatorHistoryInfo info in indicatorList)
            {
                strShow += info.IndicatorName;
                strShow += "<font style='font-size:12px;color:Red;'>("+info.DataValue + info.MeasurementUnits+")</font>";
            }
            strShow += "                            </div>";
            strShow += "                        </div>";
            strShow += "                        <div class='disease_info'>";
            strShow += "                            <div class='disease_left'><img src='/support/alpha/images/popup/popup_items.gif'/>&nbsp;治疗：</div><div class='disease_right'>";
            foreach (TreatmentHistoryInfo info in treatmentList)
            {
                strShow += "<a href=" + "../Treatment.aspx?id=" + info.TreatmentId + " class='linkclass' style='text-decoration:underline;font-size=12pt; color='Green''><font color='Green'>" + info.TreatmentName + "</font></a>";
                strShow += "<font style='font-size:12px;color:Red;'>(" + info.DataValue + info.Unit + ")</font>";
            }
            strShow += "                            </div>";
            strShow += "                        </div>  ";                 
            strShow += "                    </div>";
            strShow += "                    <div class='mypage'><a href='/Pages/Alpha/Profile/Index.aspx?uid="+userInfo.Id+"' class='mypage'style='text-decoration:underline; color:Red; font-weight:bold; font-size=12pt'>查看他(她)的病情系统</a></div>";
            strShow += "                </div>";
            strShow += "            </div>";
            strShow += "        </div>";
        }

        protected void ResponseXML(StringBuilder sb)
        {
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "Text/html";
            System.Web.HttpContext.Current.Response.Expires = 0;

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
            System.Web.HttpContext.Current.Response.End();
        }

    }
}
